﻿using HardcoreGame.Content.Items.Placeable.Banners;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.GameContent.Bestiary;
using Terraria.ID;
using Terraria.ModLoader;

namespace HardcoreGame.Content.NPCs.Enemies.Biomesa.Corruption
{
    public class CorruptedJelly : ModNPC
    {
        public override void SetStaticDefaults()
        {
            NPCID.Sets.ZappingJellyfish[Type] = true;
            var drawModifier = new NPCID.Sets.NPCBestiaryDrawModifiers()
            {
                Position = new Vector2(0f, 10f)
            };
            NPCID.Sets.NPCBestiaryDrawOffset.Add(NPC.type, drawModifier);
            Main.npcFrameCount[Type] = 7;
        }
        public override void SetDefaults()
        {
            NPC.buffImmune[31] = true;
            NPC.noGravity = true;
            NPC.width = 26;
            NPC.height = 26;
            NPC.aiStyle = 18;
            NPC.damage = 75;
            NPC.defense = 20;
            NPC.lifeMax = 150;
            NPC.HitSound = SoundID.NPCHit13;
            NPC.DeathSound = SoundID.NPCDeath19;
            NPC.value = 800f;
            NPC.alpha = 20;
            AIType = NPCID.BloodJelly;
            AnimationType = NPCID.BloodJelly;
            Banner = NPC.type;
            BannerItem = ModContent.ItemType<CorruptedJellyBanner>();
        }
        public override void HitEffect(NPC.HitInfo hit)
        {
            if (NPC.life > 0)
            {
                for (int num620 = 0; num620 < hit.Damage / (double)NPC.lifeMax * 100.0; num620++)
                {
                    Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.Corruption, hit.HitDirection, -1f);
                }
                return;
            }
            for (int num621 = 0; num621 < 50; num621++)
            {
                Dust.NewDust(NPC.position, NPC.width, NPC.height, DustID.Corruption, 2.5f * hit.HitDirection, -2.5f);
            }
            Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find<ModGore>("Gore_5").Type);
            Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find<ModGore>("Gore_6").Type);
            Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find<ModGore>("Gore_6").Type);
            Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find<ModGore>("Gore_7").Type);
            Gore.NewGore(NPC.GetSource_Death(), NPC.position, NPC.velocity, Mod.Find<ModGore>("Gore_7").Type);
        }
        public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry)
        {
            bestiaryEntry.Info.AddRange([
                BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Biomes.TheCorruption,
                new FlavorTextBestiaryInfoElement("Mods.HardcoreGame.NPCs.CorruptedJelly.Bestiary")
            ]);
        }
        public override float SpawnChance(NPCSpawnInfo spawnInfo)
        {
            int num = 0;
            int num2 = 0;
            if (spawnInfo.Player.ZoneCorrupt && spawnInfo.SpawnTileY < Main.worldSurface && Main.hardMode && Main.tile[num, num2 - 1].LiquidAmount > 0 && Main.tile[num, num2 - 2].LiquidAmount > 0 && !(Main.tile[num, num2 - 1].LiquidType == LiquidID.Lava))
            {
                return 0.1f;
            }
            return 0f;
        }
        public override void ModifyNPCLoot(NPCLoot npcLoot)
        {
            var DropRules = Main.ItemDropsDB.GetRulesForNPCID(NPCID.BloodJelly, false);
            foreach (var DropRule in DropRules)
            {
                npcLoot.Add(DropRule);
            }
        }
    }
}
